//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.system.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.SysStaff;
import com.ruoyi.system.domain.vo.StaffVo;
import com.ruoyi.system.service.ISysStaffService;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api("营销员工档案")
@RestController
@RequestMapping({"/staff"})
public class SysStaffController extends BaseController {
    @Autowired
    private ISysStaffService sysStaffService;
    @Autowired
    private ISysUserService sysUserService;

    @ApiOperation("查询营销员工档案列表")
    @RequiresPermissions({"system:staff:list"})
    @GetMapping({"/list"})
    public TableDataInfo list(SysStaff sysStaff) {
        PageDomain pageDomain = new PageDomain();
        BeanUtils.copyProperties(sysStaff, pageDomain);
        this.startPage(pageDomain);
        List<SysStaff> list = this.sysStaffService.selectSysStaffjoinSysDept(sysStaff);
        return this.getDataTable(list);
    }

    @ApiOperation("查询营销员工档案列表(不分页)")
    //@RequiresPermissions({"system:staff:list"})
    @GetMapping({"/list1"})
    public AjaxResult list1(SysStaff sysStaff) {
        List<SysStaff> list = this.sysStaffService.selectSysStaffjoinSysDept1(sysStaff);
        return AjaxResult.success(list);
    }

    @ApiOperation("查询当前供电单位下的员工列表")
    @RequiresPermissions({"system:staff:orgList"})
    @PostMapping({"/orgList"})
    public TableDataInfo orgList(@RequestBody StaffVo staffVo) {
        List<StaffVo> list = this.sysStaffService.selectOrgUserList(staffVo.getOrgNo());
        return this.getDataTable(list);
    }

    @RequiresPermissions({"system:staff:export"})
    @Log(
            title = "营销员工档案",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, @RequestBody SysStaff sysStaff) {
        List<SysStaff> list = this.sysStaffService.selectSysStaffjoinSysDept(sysStaff);
        ExcelUtil<SysStaff> util = new ExcelUtil<>(SysStaff.class);
        util.exportExcel(response, list, "营销员工档案数据");
    }

    @RequiresPermissions({"system:staff:query"})
    @GetMapping({"/info"})
    public AjaxResult getInfo(String empNo) {
        return AjaxResult.success(this.sysStaffService.selectSysStaffByEmpNo(empNo));
    }

    @RequiresPermissions({"system:staff:add"})
    @Log(
            title = "营销员工档案",
            businessType = BusinessType.INSERT
    )
    @PostMapping
    public AjaxResult add(@RequestBody SysStaff sysStaff) {
        return this.toAjax(this.sysStaffService.insertSysStaff(sysStaff));
    }

    @RequiresPermissions({"system:staff:edit"})
    @Log(
            title = "营销员工档案",
            businessType = BusinessType.UPDATE
    )
    @PostMapping({"edit"})
    public AjaxResult edit(@RequestBody SysStaff sysStaff) {
        return this.toAjax(this.sysStaffService.updateSysStaff(sysStaff));
    }

    @RequiresPermissions({"system:staff:remove"})
    @Log(
            title = "营销员工档案",
            businessType = BusinessType.DELETE
    )
    @PostMapping({"/remove"})
    public AjaxResult remove(@RequestBody String[] empNos) {
        return this.toAjax(this.sysStaffService.deleteSysStaffByEmpNos(empNos));
    }
}
